<div id="page-config" class="hidden">
  <div class="submission-active">true</div>
  <div class="title"><%= t '.submissions_list' %></div>
</div>

<table id="submissions-list" class="table table-condensed table-striped">
  <thead>
  <tr>
    <th><%= t '.id' %></th>
    <th><%= t '.score' %></th>
    <th><%= t '.user' %></th>
    <th><%= t '.problem' %></th>
    <th><%= t '.time_used' %></th>
    <th><%= t '.memory_used' %></th>
    <th><%= t '.language' %></th>
    <th><%= t '.platform' %></th>
    <th><%= t '.code_length' %></th>
    <th><%= t '.code_size' %></th>
    <th><%= t '.submit_time' %></th>
  </tr>
  </thead>
  <tbody>
  <% @submissions.each do |submission| %>
    <tr class="<%= 'warning' if owner?(submission) %>">
      <td>
        <% if submission.share || @current_user && (submission.user_id == @current_user.id || @current_user.role == 'admin') %>
          <%= submission_link submission.id %>
        <% else %>
          <%= submission.id %>
        <% end %>
      </td>
      <% if submission.status == 'waiting' %>
        <td style="color: darkgoldenrod"><%= t '.waiting' %></td>
      <% elsif submission.status == 'running' %>
        <td style="color: darkorange"><%= t '.running' %></td>
      <% else %>
        <% if submission.score == 100 %>
          <td style="color: green;"><%= submission.score %></td>
        <% else %>
          <td style="color: red;"><%= submission.score %></td>
        <% end %>
      <% end %>
      <td><%= user_link submission.user.handle %></td>
      <td><%= problem_link submission.problem_id %></td>
      <td><%= format_time_used submission.time_used %></td>
      <td><%= format_memory_used submission.memory_used %></td>
      <td><%= format_language submission.language %></td>
      <td><%= format_platform submission.platform %></td>
      <td><%= submission.code_length %></td>
      <td><%= format_code_size submission.code_size %></td>
      <td><%= format_datetime submission.created_at %></td>
    </tr>
  <% end %>
  </tbody>
</table>

<ul class="pager">
  <% if @page > 1 %>
    <li><%= link_to t('.last_page'), submissions_list_path(@page - 1, params.to_hash) %></li>
  <% end %>
  <% unless @is_last_page %>
    <li><%= link_to t('.next_page'), submissions_list_path(@page + 1, params.to_hash) %></li>
  <% end %>
</ul>

<% cache_if(params[:choose_all] && !params[:handle] && !params[:problem_id] && !params[:min_score] && !params[:max_score], action_suffix: 'toolbar') do %>
  <div id="toolbar" class="hidden">
    <ul class="nav pull-right">
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="outline: none;">
          <%= t '.toolbar.filter' %><b class="caret"></b>
        </a>
        <div id="submissions-filter-dropdown" class="dropdown-menu">
          <%= form_tag submissions_list_path, method: :get do %>
            <div class="dropdown-container clearfix">
              <div class="row-fluid">
                <input type="text" class="span6" name="handle" maxlength="15" placeholder="<%= t '.toolbar.user' %>"
                       value="<%= params[:handle] || '' %>">
                <input type="text" class="span6" name="problem_id" maxlength="4" placeholder="<%= t '.toolbar.problem' %>"
                       value="<%= params[:problem_id] || '' %>">
              </div>
              <div class="row-fluid">
                <input type="text" class="span6" name="min_score" maxlength="3" placeholder="<%= t '.toolbar.min_score' %>"
                       value="<%= params[:min_score] || '' %>">
                <input type="text" class="span6" name="max_score" maxlength="3" placeholder="<%= t '.toolbar.max_score' %>"
                       value="<%= params[:max_score] || '' %>">
              </div>
              <div class="row-fluid">
                <div class="span3">
                  <div style="margin-top: 5px; margin-left: 5px;">
                    <%= t '.toolbar.language' %>
                  </div>
                </div>
                <div class="span9">
                  <% APP_CONFIG.program_languages.each do |key, value| %>
                    <label class="checkbox inline item">
                      <input type="checkbox" name="language_<%= key %>" value="1"
                             <%= %q{checked="checked"} if params["language_#{key}"] || params[:choose_all] %>>
                      <%= value %>
                    </label>
                  <% end %>
                </div>
              </div>
              <div class="row-fluid">
                <div class="span3">
                  <div style="margin-top: 5px; margin-left: 5px;">
                    <%= t '.toolbar.platform' %>
                  </div>
                </div>
                <div class="span9">
                  <% APP_CONFIG.judge_platforms.each do |key, value| %>
                    <label class="checkbox inline item">
                      <input type="checkbox" name="platform_<%= key %>" value="1"
                             <%= %q{checked="checked"} if params["platform_#{key}"] || params[:choose_all] %>>
                      <%= value %>
                    </label>
                  <% end %>
                </div>
              </div>
              <button type="submit" class="pull-right btn"><%= t '.toolbar.filter' %></button>
            </div>
          <% end %>
        </div>
      </li>
    </ul>
  </div>
<% end %>
